#!/bin/sh
#if the pkg created in packages-woof has something wrong, this file is a last
#resort to fix it. Current-dir is where this file FIXUPHACK is located.

# Xorg/X is in xserver-xorg..
rm -f usr/bin/X

#slackware: /etc/X11/xkb
#debian   : /usr/share/X11/xkb

#slackware: usr/share/X11/xkb/ is already a symlink..
#           created by the slackware post-install script (most likely)
if [ ! -L usr/share/X11/xkb ] ; then
	#debian
	mv -f usr/share/X11/xkb/* etc/X11/xkb/ 2>/dev/null
	rm -rf usr/share/X11/xkb/
	ln -sv ../../../etc/X11/xkb usr/share/X11/xkb
fi

# http://packages.slackware.com/?r=slackware-14.2&p=libX11-1.6.4-i586-1_slack14.2.txz&f
# http://packages.ubuntu.com/xenial/libx11-data -> http://packages.ubuntu.com/xenial/all/libx11-data/filelist
# slackware: libX11
# debian:    libX11-data
# keep: C en_US.UTF-8 iso8859-1 iso8859-2 iso8859-15 [following old template]
# pkg template should not have 'nls>null'. Have to copy stuff from NLS dir.
#   ,nls     is the preferred option
#   ,nls>exe is acceptable
if [ -d ../xorg_base_new_NLS ] ; then
	mkdir -p usr/share/X11/locale/
	cp -af ../xorg_base_new_NLS/usr/share/X11/locale/* usr/share/X11/locale/
else
	if [ ! -d usr/share/X11/locale/C ] ; then
		echo '!!! ERROR: ../xorg_base_new_NLS MISSING !!!'
	fi
fi
find usr/share/X11/locale  -mindepth 1 -maxdepth 1 -type d | \
	grep -Ev '/C$|/en_US.UTF-8$|/iso8859-1$|/iso8859-2$|/iso8859-15$' | \
		while read dir ; do
			rm -rf "$dir"
		done


# ancient libxcb-xlib.so.0 .. tried to run 'viewnior' pkg from wary, missing 'libxcb-xlib.so.0'...
if [ -f usr/${PLIB}/libX11.so.6 ] ; then
	ln -sv libX11.so.6 usr/${PLIB}/libxcb-xlib.so.0 #dummy link.
elif [ -f usr/lib/${ARCHDIR}/libX11.so.6 ] ; then
	ln -sv libX11.so.6 usr/lib/${ARCHDIR}/libxcb-xlib.so.0 #dummy link.
fi

for i in $PLIBDIRS # $PLIBDIRS is exported in 2createpackages
do
	[ -d $i ] || continue
	#100416 ubuntu lucid has moved libGL.so* to /usr/lib/mesa (why oh why!!!???)...
	#note, but not libGLU.so*
	if [ -e ${i}/mesa/libGL.so.1 ];then
		ln -sv mesa/libGL.so.1 ${i}/libGL.so.1
		ln -sv mesa/libGL.so ${i}/libGL.so
		ln -sv mesa/libGL.so.1.2 ${i}/libGL.so.1.2
	fi
done

rm -f usr/bin/xmessage

#===================================

#if /etc/fonts/fonts.conf is not present, use traditional Puppy-style font settings
if [ -f etc/fonts/fonts.conf ];then
	rm -rf etc/fonts-puppy
else
	rm -rf etc/fonts
	mv etc/fonts-puppy etc/fonts
fi

ln -sv ../../../etc/X11/app-defaults usr/share/X11/app-defaults
rm -rf etc/X11/xinit

mkdir -p var/cache/fontconfig

# Bitmaps that are shared between X applications are in an odd place..
if [ -d ../xorg_base_new_DEV/usr/include/X11/bitmaps ] ; then
	mkdir -p usr/include/X11/
	mv -f ../xorg_base_new_DEV/usr/include/X11/bitmaps usr/include/X11/
fi

#====================================================

mkdir -p usr/share/applications
if [ -f usr/bin/xcalc ] ; then
	cat > usr/share/applications/Xcalc-scientific-calculator.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Xcalc scientific calculator
Icon=/usr/share/pixmaps/puppy/calculator.svg
Comment=Xcalc scientific calculator
Exec=xcalc
Terminal=false
Type=Application
Categories=Calculator
GenericName=Xcalc scientific calculator
EOF
fi

### END ###